package com.example.e11_q3;

/**
 * @desc:
 * @author: Shoko
 * @date: 2025/6/13
 */
import java.util.HashMap;
import java.util.Map;

public class FinanceDepartmentVisitor implements EmployeeVisitor {
    // 按部门统计工资支出
    private Map<String, Integer> deptSalaries = new HashMap<>();

    @Override
    public void visit(RegularEmployee employee) {
        String dept = employee.getDepartment();
        int base = employee.getBaseSalary();
        int leaveHours = employee.getLeaveHours();
        int salary;

        if (leaveHours > 0) {
            // 请假：扣除工资（最多扣到0）
            salary = Math.max(base - leaveHours * 80, 0);
        } else {
            // 加班：基本工资 + 加班工资（100元/小时）
            salary = base + (-leaveHours) * 100;
        }

        // 累加部门工资
        deptSalaries.put(dept, deptSalaries.getOrDefault(dept, 0) + salary);
    }

    @Override
    public void visit(TemporaryEmployee employee) {
        String dept = employee.getDepartment();
        // 临时工工资 = 实际时长 × 小时工资
        int salary = employee.getActualHours() * employee.getHourlyWage();
        deptSalaries.put(dept, deptSalaries.getOrDefault(dept, 0) + salary);
    }

    // 输出财务部统计结果
    public void showReport() {
        System.out.println("=== 财务部统计报告 ===");
        deptSalaries.forEach((dept, salary) ->
                System.out.println("部门 [" + dept + "] 总工资支出: " + salary + " 元")
        );
    }
}
